import absSubAction from "../abssubcmdaction";
import globalConst from "../../../canvas/common/globalConst.js";
var global = globalConst.GlobalConst;
import {LGXEnums}  from "../../../canvas/common/sysenum";

import cmdenums from "../cmdenums";

class LineDrawAction extends absSubAction.AbsSubAction {
    constructor() {
        super();
        this.mainCMD = cmdenums.DrawCmdType.line;
    }

    actCMD(type, val, mainctl) {
        let actRst = null;
        let nextTips = "";
        if (type == 'l') {
            let type = parseInt(val);
            let toolKind = global.BaseUnitPolyline;
            toolKind = toolKind << 16;
            if (type != 0 && type>>16 ==global.BaseUnitPolyline){
                toolKind = type;
            }
            mainctl.setCMDTool(toolKind);
            nextTips = "输入起点坐标或在图中鼠标左键点击确定坐标:x,y";
            let cmd = { type: 'l', value: "" };
            actRst = { cmdObj: cmd, nextTips, appendToPreCMD:"", finish: false };
        }
        else {
            actRst = this.act2InPlottingCMD(type,mainctl);
        }
        return actRst;
    }

    actCanvasEvt(evt, mainctl) {
        let actRst = null;
        if (evt.eventKind == LGXEnums.LGXEventKind.StartDrawNewTool) {
            let cmd = new absSubAction.TCmd();
            cmd.type = 'l';
            cmd.value = "";
            let nextTips = "输入起点坐标或在图中鼠标左键点击确定坐标:x,y";
            let appendToPreCMD = "l";
            actRst = { cmdObj: cmd, nextTips, appendToPreCMD };
        }
        else if (evt.eventKind == LGXEnums.LGXEventKind.FinishDraw) {
            let cmd = new absSubAction.TCmd();
            cmd.type = 'e';
            cmd.value = "";
            actRst = { cmdObj: cmd, nextTips:"", appendToPreCMD:"e",finish:true };
        }
        else if (evt.mouseDownTime > 0) {
            let coordDecs = evt.wx.toFixed(2) + "," + evt.wy.toFixed(2);
            let cmd = new absSubAction.TCmd();
            cmd.type = 'draw_lmousedown';
            cmd.value = coordDecs;
            let nextTips = "输入下一点坐标或在图中鼠标左键点击确定坐标:x,y,相对坐标使用:@x,@y。结束（e）";
            if (evt.mouseDownTime > 2) {
                nextTips = "输入下一点坐标或在图中鼠标左键点击确定坐标:x,y,相对坐标使用:@x,@y。闭合（c），结束（e）";
            }
            let appendToPreCMD = coordDecs;
            actRst = { cmdObj: cmd, nextTips, appendToPreCMD };
        }
        return actRst;
    }
}

export default { LineDrawAction }